package com.example.bmi;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.text.DecimalFormat;

public class MainActivity extends AppCompatActivity {
    public  static  final  String TAG="mylog";
    TextView bmi;
    TextView adv;
    EditText edit1;
    EditText edit2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bmi=findViewById(R.id.textView1);
        adv=findViewById(R.id.textView2);

        edit1=findViewById(R.id.inp1);
        edit2=findViewById(R.id.inp2);


    }
    public void myclick(View v) {
        String s1=edit1.getText().toString();
        String s2=edit2.getText().toString();
        double height=Double.parseDouble(s1);
        double weight=Double.parseDouble(s2);
        double s3=weight/(height*height);
        DecimalFormat df = new DecimalFormat("#####0.00");
        String s4 = df.format(s3);
        double s5=Double.parseDouble(s4);
        String s6;
        if (s5<20){
            s6="体重过低";
        }else if (s5<25){
            s6="正常";
        }else if (s5<30){
            s6="超重";
        }else{
            s6="肥胖";
        }

        Log.i(TAG,"myclick():height="+height);
        Log.i(TAG,"myclick():weight="+weight);
        Log.i(TAG,"myclick():BMI="+weight/height);
        bmi.setText("BMI："+s4);
        adv.setText("健康建议："+s6);

    }
}